package ru.ncedu.java.vlku.hrs.uil.cmd;

import ru.ncedu.java.vlku.hrs.bll.HRSManager;
import ru.ncedu.java.vlku.hrs.bll.HRSManagerFactory;
import ru.ncedu.java.vlku.hrs.model.Shop;

import java.util.List;

public class GetShop implements Command {
    // get shop by id <id>
    // get shop by name <name>
    @Override
    public void execute(String[] args) {
        if (args.length != 5 || !args[2].equals("by"))
            throw new IllegalArgumentException();
        HRSManager manager = HRSManagerFactory.getInstance().getHRSManager();
        if (args[3].equals("id")) {
            Long id = Long.parseLong(args[4]);
            Shop shop = manager.getShopById(id);
            System.out.println("Id\tName\tAddress");
            System.out.println(shop.getId() + "\t" + shop.getName() + "\t" + shop.getAddress());
        } else if (args[3].equals("name")) {
            List<Shop> shops = manager.getShopsWithName(args[4]);
            System.out.println("Id\tName\tAddress");
            for (int i = 0; i < shops.size(); i++)
                System.out.println(shops.get(i).getId() + "\t" + shops.get(i).getName() + "\t" + shops.get(i).getAddress());
        } else
            throw new IllegalArgumentException();
    }
}
